﻿using street.GameDllInterfaces;
using System;
using System.Windows.Forms;
using static WorldRacing2.Street1Addin;

namespace WorldRacing2.StreetAddin.Street
{
    public partial class VertexDataControl : UserControl, street.GameDllInterfaces.IStreetAddinControl
    {
        #region Public Constructors

        public VertexDataControl()
        {
            InitializeComponent();
        }

        #endregion Public Constructors

        #region Public Events

        public event EventHandler ValueChanged;

        #endregion Public Events

        #region Public Methods

        DataForGamevertexCalclation IStreetAddinControl.GetVertexCreationData()
        {
            //MessageBox.Show("Get Data");
            VertexColors vertexColors = new VertexColors()
            {
                vertexColorEndLeft = this.panel_VertexColorEnd.BackColor,
                vertexColorEndRight = this.panel_VertexColorRight.BackColor,
                vertexColorStartLeft = this.panel_VertexColorLeft.BackColor,
                vertexColorStartRight = this.panel_VertexColorStart.BackColor
            };

            return new DataForGamevertexCalclation()
            {
                version = 1,
                gameDllData = vertexColors
            };
        }

        void IStreetAddinControl.SetControlProperties(DataForGamevertexCalclation data)
        {
            //MessageBox.Show("Set Data");

            VertexColors vertexColors = (VertexColors)data.gameDllData;

            this.panel_VertexColorEnd.BackColor = vertexColors.vertexColorEndLeft;
            this.panel_VertexColorRight.BackColor = vertexColors.vertexColorEndRight;
            this.panel_VertexColorLeft.BackColor = vertexColors.vertexColorStartLeft;
            this.panel_VertexColorStart.BackColor = vertexColors.vertexColorStartRight;
        }

        #endregion Public Methods

        #region Private Methods

        private void panel_VertexColor_BackColorChanged(object sender, EventArgs e)
        {
            if (ValueChanged != null)
                ValueChanged(sender, e);
            else
                throw new Exception("No event is registered for Vertex Color change.");
        }

        private void panel_VertexColorStart_DoubleClick(object sender, EventArgs e)
        {
            Panel panel = (Panel)sender;
            ColorDialog colorDialog = new ColorDialog();

            if (DialogResult.OK == colorDialog.ShowDialog())
            {
                panel.BackColor = colorDialog.Color;
            }
        }

        private void panel_VertexColorStart_MouseHover(object sender, EventArgs e)
        {
            this.toolTip1.Show("Doubleclick to change the vertexcolor. (Start, End, Left, Right)", this.groupBox_VertexColor, 0, -10);
        }

        private void panel_VertexColorStart_MouseLeave(object sender, EventArgs e)
        {
            this.toolTip1.Hide(this.groupBox_VertexColor);
        }

        #endregion Private Methods
    }
}